import Vue from 'vue'
import Vuex from 'vuex'

import {
  eduLessonQuery,
  eduLessonDelete,
  eduLessonAdd,
  eduLessonUpdate,
} from '@/api/admin/courseLibrary/eduLesson.js'

Vue.use(Vuex)

const state = {
  curLessonPlan: {},
}

const getters = {
  curLessonPlan: (state) => state.curLessonPlan,
}

const actions = {
  async queryEduLesson({ commit }, listQuery) {
    let res = await eduLessonQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async deleteEduLesson({ commit }, row) {
    let res = await eduLessonDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addEduLesson({ commit }, data) {
    let res = await eduLessonAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateEduLesson({ commit }, data) {
    let res = await eduLessonUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {
  setCurLessonPlan: (state, d) => (state.curLessonPlan = d),
}

export default {
  state,
  getters,
  actions,
  mutations,
}
